//
//  XiaoJianPanLianXiViewController.swift
//  ZHM
//
//  Created by zzddongge on 16/7/26.
//  Copyright © 2016年 zzd. All rights reserved.
//

import UIKit

class XiaoJianPanLianXiViewController: UIViewController,UITextViewDelegate,UITextFieldDelegate,UIActionSheetDelegate{

    //获取模拟器或者真机的宽度和高度
    let screenWidth = UIScreen.main.bounds.width
    let screenHeight = UIScreen.main.bounds.height
    
    //定义导航栏的高度
    var navigationHeight:CGFloat?
    
    
    //定义三个UIView,用于分割成四个模块
    var leftView:UIView?
    var middleView:UIView?
    var rightView:UIView?
    
    //创建8个UILabel对象
    var zhengQueShuLabel:UILabel?
    var zhengQueShuLabelValue:UILabel?
    
    var zhengQueLvLabel:UILabel?
    var zhengQueLvLabelValue:UILabel?
    
    var shiJianLabel:UILabel?
    var shiJianLabelValue:UILabel?
    
    var suDuLabel:UILabel?
    var suDuLabelValue:UILabel?
    
    
    //定义一条横线UIView
    var hengXianView:UIView?
    
   
    //定义6个UIlabel对象,用于存储随机生成的6个数字
    var firstLabel:UILabel?
    var secondLabel:UILabel?
    var thirdLabel:UILabel?
    var fourthLabel:UILabel?
    var fifthLabel:UILabel?
    var sixthLabel:UILabel?
    
    //定义6个UITextField对象,用于存储用户输入的值
    var firstTextFieldValue:UITextField?
    var secondTextFieldValue:UITextField?
    var thirdTextFieldValue:UITextField?
    var fourthTextFieldValue:UITextField?
    var fifthTextFieldValue:UITextField?
    var sixthTextFieldValue:UITextField?
    
    //定义一个变量,用于存储随机生成的数字
    var randomNumber:Int?
    
    //创建一个弹出层
    var tanChuCengAlertView:CustomIOS7AlertView?
    
    //定义一个UIView,用于存储alertView中的控件
    var showAlertViewContentView:UIView?
    
    //定义一个数组,用于存储segment中控件的类别
    var segmentArray = ["计时模式","定时模式"]
    
    //定义两个ActionSheet:数字个数ActionSheet,练习时间ActionSheet
    //数字个数ActionSheet
    var shuZiGeShuActionSheet:UIActionSheet?
    //练习个数ActionSheet
    var lianXiTimeActionSheet:UIActionSheet?
    
    //定义一个变量,用于保存actionSheet中的三个值
    var actionSheetValue:String?
    
    var selectedActionSheetValue:String?
    //定义选中的数字个数Label
    var selectedActionSheetValueLabel:UILabel?
    
    //定义选中的分钟actionSheet
    var selectedMinuteActionSheetValueLabel:UILabel?
    
    //定义一个定时器
    var timer:Timer!
    //定义一个变量:保存计时器时间的值
    var timerValue:Int = 0
    
    //定义一个变量selectedXunLianShuZiGeShuZhi,用于保存选中的训练数字的个数值
    var selectedXunLianShuZiGeShuZhi:Int = 0
    //定义一个变量selectedXunLianFenZhongZhi,用于保存选中的训练分钟值
    var selectedXunLianFenZhongZhi:Int = 0
    
    //定义一个变量,用于存储随机生成的0-5之间的数字
    var randomNumberBetweenZeroAndFive:Int?
    //定义一个Int类型的数组
    var randomNumberArray:[Int] = []
    
    override func viewDidLoad() {
        fengZhuangViewDidLoad()

        super.viewDidLoad()
    }
    
    /*
        作者:张振东
        日期:2016-8-29
        功能:用户点击"点击这里开始"按钮开始进行训练,传递选中的值到相应的UIlabel对象
     */
    func customIOS7dialogButtonTouchUpInside(_ alertView: Any!, clickedButtonAtIndex buttonIndex: Int) {
        //表示用户点击了第一个按钮
        if buttonIndex == 0{
            //将选中的值传递到相应的label对象中
            print(selectedActionSheetValueLabel?.text! as Any)
            print(selectedMinuteActionSheetValueLabel?.text as Any)
            if let selectedXunLianShuZiGeShuZhi = selectedActionSheetValueLabel?.text{
                self.selectedXunLianShuZiGeShuZhi = Int(selectedXunLianShuZiGeShuZhi)!
                print(selectedXunLianShuZiGeShuZhi)//4
                
                //将选中的随机的label对象的个数传递给函数baoCunSuiJiShengChengDeShuZi
                let array:[Int] = baoCunSuiJiShengChengDeShuZi(UInt32(self.selectedXunLianShuZiGeShuZhi))
                print(array)
                //遍历array
//                bianLiSuiJiArray(array)
            }
            
            if let selectedXunLianFenZhongZhi = selectedMinuteActionSheetValueLabel?.text{
                self.selectedXunLianFenZhongZhi = Int(selectedXunLianFenZhongZhi)!
                
                print(selectedXunLianFenZhongZhi)//4
                
                timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(genJuSelectedValueJiShi), userInfo: nil, repeats: true)
                
            }
            
            //关闭alertView
            //alertView.close()
        }
    }
    
    
    /*
     作者:张振东
     日期:2016-09-06
     功能:显示计时时间
     */
    func genJuSelectedValueJiShi(){
        timerValue += 1
        print("选中的分钟值为:\(self.selectedXunLianFenZhongZhi)")
        //获得分钟
        let fenZhongValue = timerValue/60
        //获取秒数
        let miaoValue = timerValue%60
        
        if fenZhongValue < 10 {
            if miaoValue < 10 {
                shiJianLabelValue?.text = "00:0\(fenZhongValue):0\(miaoValue)"
            }else{
                shiJianLabelValue?.text = "00:0\(fenZhongValue):\(miaoValue)"
            }
        }else{
            if miaoValue < 10{
                shiJianLabelValue?.text = "00:\(fenZhongValue):0\(miaoValue)"
            }else{
                shiJianLabelValue?.text = "00:\(fenZhongValue):\(miaoValue)"
            }
        }
        
        //当计时结束时,可以在此进行if语句中显示最终的结果
        if timerValue == self.selectedXunLianFenZhongZhi * 60{
            timer.invalidate()
            print("倒计时结束")
        }
        
        print(timerValue)
    }
    
    
    /*
        日期:2016-09-06
        作者:张振东
        功能:使用数组保存随机生成的0-5之间的数字,返回一个[Int]类型的数组
     */
    func baoCunSuiJiShengChengDeShuZi(_ randomNumberBetweenZeroAndFive : UInt32) -> [Int]{
        print(randomNumberBetweenZeroAndFive)
        for index in 0...randomNumberBetweenZeroAndFive-1{
            self.randomNumberBetweenZeroAndFive = Int(arc4random_uniform(6))
            
            
            for indexs in randomNumberArray{
                if randomNumberArray.contains(self.randomNumberBetweenZeroAndFive!){
                    randomNumberArray.append(self.randomNumberBetweenZeroAndFive!)
                    //let indexs = randomNumberArray.indexOf(self.randomNumberBetweenZeroAndFive!)
                    randomNumberArray.remove(at: Int(indexs))
                    
                    continue
                }else{
                    randomNumberArray.append(self.randomNumberBetweenZeroAndFive!)
                }

            }
            
            //遍历数组,删除重复的数字
//           bianLiSuiJiArray(randomNumberArray)
            
        }
        return randomNumberArray
    }
    
    /*
     日期:2016-09-06
     作者:张振东
     功能:遍历随机生成的整型数组
     */
    func bianLiSuiJiArray(_ array : [Int]){
        for index in array{
            print("\(array[index])")
            
        }
    }
    
    
    
    /*
        日期:2016-8-16
        作者:张振东
        功能:点击"选择训练数字个数"按钮时,弹出actionSheet,供用户选择
    */
    func xuanZeXunLianShuZi(){
        shuZiGeShuActionSheet = UIActionSheet(title: "选择训练数字个数",delegate: self,cancelButtonTitle:"取消",destructiveButtonTitle:nil,otherButtonTitles:"4","5","6" )
        shuZiGeShuActionSheet!.delegate = self
        shuZiGeShuActionSheet!.show(in: showAlertViewContentView!)
    }
    
    /*
        日期:2016-8-16
        作者:张振东
        功能:点击"练习时间"按钮时,弹出actionSheet,供用户选择
     */
    func xuanZeLianXiTime(){
        lianXiTimeActionSheet = UIActionSheet(title: "练习时间",delegate: self,cancelButtonTitle: "取消",destructiveButtonTitle: nil,otherButtonTitles: "1","2","3","4","5","6","7","8","9","10")
        lianXiTimeActionSheet!.delegate = self
        lianXiTimeActionSheet!.show(in: showAlertViewContentView!)
    }
    
    /*
        日期:2016-8-29
        作者:张振东
        功能:点击actionSheet中的选项,获取选中的值
     */
    func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int) {
        if actionSheet == shuZiGeShuActionSheet{
        
            switch buttonIndex {
            //buttonIndex为0时表示,点击的是取消按钮
            case 0:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedActionSheetValueLabel!)
                
            case 1:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedActionSheetValueLabel!)
                

            case 2:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedActionSheetValueLabel!)
            case 3:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedActionSheetValueLabel!)
                

            default:
                print("请选择正确的值")
            }

        }else if actionSheet == lianXiTimeActionSheet{
            switch buttonIndex {
            //buttonIndex为0时表示,点击的是取消按钮
            case 0:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 1:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 2:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 3:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 4:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 5:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 6:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 7:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 8:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 9:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            case 10:
                fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(actionSheet, buttonIndex: buttonIndex, label: selectedMinuteActionSheetValueLabel!)
            default:
                print("请选择正确的值")
            }
        }
    
    }
    
    
    
    
    /*
        作者:张振东
        时间:2016-8-28
        功能:根据选中的actionSheet下标,得到选中的actionSheet值,然后将其赋值给制定的label对象
     */
    func fengZhuangSelectedButtonIndexAndDeDaoValueAndFuZhiGeiLabel(_ actionSheet:UIActionSheet,buttonIndex:Int,label:UILabel){
    
        switch label {
        case selectedActionSheetValueLabel!:
            actionSheetValue = actionSheet.buttonTitle(at: buttonIndex)
            if let actionSheetValue = actionSheetValue{
                selectedActionSheetValue = actionSheetValue
                selectedActionSheetValueLabel?.text = selectedActionSheetValue
            }
        case selectedMinuteActionSheetValueLabel!:
            actionSheetValue = actionSheet.buttonTitle(at: buttonIndex)!
            if let actionSheetValue = actionSheetValue{
                selectedActionSheetValue = actionSheetValue
                print(selectedActionSheetValue as Any)
                selectedMinuteActionSheetValueLabel?.text = selectedActionSheetValue
            }
            break
            
        default:
            print("请选择正确的值")
        }
    }
    
    
    override func viewDidAppear(_ animated: Bool) {
        
        //自定义UINavigationBar控件
        let navigationBar = self.navigationController?.navigationBar
        navigationBar?.barStyle = .black
        let clockImageView = UIImageView(frame:CGRect(x:0,y:0,width:40,height:40))
        clockImageView.contentMode = .scaleAspectFit
        let image = UIImage(named: "clock")
        clockImageView.image = image
        navigationItem.titleView = clockImageView
        
        //创建UINavigationBar的右侧按钮
        let rightBarButtonItem = UIButton(frame:CGRect(x: screenWidth-200,y: 0,width: 40,height: 40))
        let zanTingImage = UIImage(named: "zanting")
        rightBarButtonItem.setBackgroundImage(zanTingImage, for: UIControlState())
        let zanTingItem = UIBarButtonItem(customView: rightBarButtonItem)
        self.navigationItem.rightBarButtonItem = zanTingItem
    }

    
    //返回至上一个界面
    func backToPrevious(){
        self.navigationController?.popViewController(animated: true)
    }
    
    
    
    
    /*
        作者:张振东
        时间:2016-8-11
        功能:封装UIlabel对象的属性®
     */
    @discardableResult
    func fengZhuangLabelAttributes(_ label:UILabel) -> UILabel{
    
        label.backgroundColor = UIColor.brown
        label.font = UIFont.systemFont(ofSize: 12)
        label.textAlignment = .center
        
        switch label {
        case zhengQueShuLabel!:
            label.text = "正确数"
        case zhengQueShuLabelValue!:
            label.text = "0"
        case zhengQueLvLabel!:
            label.text = "正确率"
        case zhengQueLvLabelValue!:
            label.text = "0%"
        case shiJianLabel!:
            label.text = "时间"
        case shiJianLabelValue!:
            label.text = "00:00:00"
        case suDuLabel!:
            label.text = "速度"
        case suDuLabelValue!:
            label.text = ""
        
        default: break
        
        }
        return label
    }
    
    
    /*
        作者:张振东
        日期:2016-8-11
        功能:用变量存储随机生成的0-9之间的数字
     */
    func generateRandomNumber(){
        for index in 0...5 {
            if index == 0{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    firstLabel?.text = "\(randomNumber)"
                }
                
            }else if index == 1{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    secondLabel?.text = "\(randomNumber)"
                }
                
            }else if index == 2{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    thirdLabel?.text = "\(randomNumber)"
                }
                
            }else if index == 3{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    fourthLabel?.text = "\(randomNumber)"
                }
                
            }else if index == 4{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    fifthLabel?.text = "\(randomNumber)"
                }
                
            }else if index == 5{
                randomNumber = Int(arc4random_uniform(10))
                if let randomNumber = randomNumber{
                    sixthLabel?.text = "\(randomNumber)"
                }
                
            }
            
            
        }
    }
    
    /*
     作者:张振东
     日期:2016-8-11
     功能:实现textView中的textViewDidChange()方法
     */
    func textViewDidChange(_ textView: UITextView) {
        
        print(textView.text)
        print(firstTextFieldValue?.tag as Any)
        if firstTextFieldValue?.tag == 0{
            if let textViewValue = textView.text{
                firstTextFieldValue?.text = textViewValue
                if (firstTextFieldValue?.text)! == firstLabel?.text{
                        
//                    secondTextFieldValue?.becomeFirstResponder()
                }
            }
        }
        
    }
    
    /*
     日期:2016-8-13
     作者:张振东
     功能:实现不断的输入数字进行训练
     */
    func textFieldDidEndEditing(_ textField: UITextField) {
        print(textField.text as Any)
        switch textField.tag {
        case 1:
            if let textViewValue = textField.text{
                secondTextFieldValue?.text = textViewValue
//                thirdTextFieldValue?.becomeFirstResponder()
            }

        case 2:
            if let textViewValue = textField.text{
                thirdTextFieldValue?.text = textViewValue
//                fourthTextFieldValue?.becomeFirstResponder()
            }
        case 3:
            if let textViewValue = textField.text{
                fourthTextFieldValue?.text = textViewValue
//                fifthTextFieldValue?.becomeFirstResponder()
            }
        case 4:
            if let textViewValue = textField.text{
                fifthTextFieldValue?.text = textViewValue
//                sixthTextFieldValue?.becomeFirstResponder()
            }
        case 5:
            if let textViewValue = textField.text{
                sixthTextFieldValue?.text = textViewValue
                if sixthTextFieldValue?.text == sixthLabel?.text{
                    firstTextFieldValue?.text = ""
                    secondTextFieldValue?.text = ""
                    thirdTextFieldValue?.text = ""
                    fourthTextFieldValue?.text = ""
                    fifthTextFieldValue?.text = ""
                    sixthTextFieldValue?.text = ""
                    //开始下一轮的时候进行重新分配数字
                    generateRandomNumber()
                    
                }
            }
        default:
            print(1)
        }
        
    }
//    func textFieldDidEndEditing(textField: UITextField) {
//        print(textField.text)
//        if let secondTextFieldValue = textField.text{
//            print(secondTextFieldValue)//7
//              if let secondLabelValue = secondLabel?.text{
//                print(secondLabelValue)
//                if secondTextFieldValue == secondLabelValue{
//                    thirdTextFieldValue?.becomeFirstResponder()
//                    
//                }
//            }
//        }
//        
//    }
// 

    /*
     作者:张振东
     日期:2016-8-12
     功能:实现封装viewDidLoad中初始化的代码
     */
    func fengZhuangViewDidLoad(){
        let leftBarBtn = UIBarButtonItem(title: "<", style: .plain, target: self,action: #selector(backToPrevious))
        self.navigationItem.leftBarButtonItem = leftBarBtn
        self.view.backgroundColor = UIColor.white
        
        //定义一个textView,用于初始化一个键盘
        var jianPanTextView:UITextView?
        
        //获取导航栏的高度
        navigationHeight = self.navigationController?.navigationBar.layer.bounds.height
        print(navigationHeight as Any)
        //初始化leftView
        leftView = UIView(frame:CGRect(x:screenWidth/4,y:navigationHeight!+30,width:1,height:70))
        leftView?.backgroundColor = UIColor(red: 200/255,green: 199/255,blue: 204/255,alpha: 1)
        
        //初始化middleView
        middleView = UIView(frame:CGRect(x: screenWidth/2,y:navigationHeight!+30,width:1,height:70))
        middleView?.backgroundColor = UIColor(red: 200/255,green: 199/255,blue: 204/255,alpha: 1)
        
        //初始化rightView
        rightView = UIView(frame:CGRect(x: (screenWidth/4)*3,y:navigationHeight!+30,width:1,height:70))
        rightView?.backgroundColor = UIColor(red: 200/255,green: 199/255,blue: 204/255,alpha: 1)
        
        //初始化六个UIlabel对象
        //初始化第一个UIlabel对象
        zhengQueShuLabel = UILabel(frame:CGRect(x: (screenWidth/4-60)/2,y: navigationHeight!+30,width: 60,height: 30))
        fengZhuangLabelAttributes(zhengQueShuLabel!)
        
        
        //初始化第二个UIlabel对象
        zhengQueShuLabelValue = UILabel(frame:CGRect(x: (screenWidth/4-60)/2,y: navigationHeight!+70,width: 60,height: 30))
        fengZhuangLabelAttributes(zhengQueShuLabelValue!)
        
        //初始化第三个UILabel对象
        zhengQueLvLabel = UILabel(frame:CGRect(x: screenWidth/4+(screenWidth/4-60)/2,y: navigationHeight!+30,width: 60,height: 30))
        fengZhuangLabelAttributes(zhengQueLvLabel!)
        
        //初始化第四个UILabel对象
        zhengQueLvLabelValue = UILabel(frame:CGRect(x: screenWidth/4+(screenWidth/4-60)/2,y: navigationHeight!+70,width: 60,height: 30))
        fengZhuangLabelAttributes(zhengQueLvLabelValue!)
        
        //初始化第五个UIlabel对象
        shiJianLabel = UILabel(frame:CGRect(x: screenWidth/2+(screenWidth/4-60)/2,y: navigationHeight!+30,width: 60,height: 30))
        fengZhuangLabelAttributes(shiJianLabel!)
        
        
        //初始化第六个UIlabel对象
        shiJianLabelValue = UILabel(frame:CGRect(x: screenWidth/2+(screenWidth/4-60)/2,y: navigationHeight!+70,width: 60,height: 30))
        fengZhuangLabelAttributes(shiJianLabelValue!)
        
        //初始化第七个UIlabel对象
        suDuLabel = UILabel(frame:CGRect(x: (screenWidth/4)*3+(screenWidth/4-60)/2,y: navigationHeight!+30,width: 60,height: 30))
        fengZhuangLabelAttributes(suDuLabel!)
        
        //初始化第八个UIlabel对象
        suDuLabelValue = UILabel(frame:CGRect(x: (screenWidth/4)*3+(screenWidth/4-60)/2,y: navigationHeight!+70,width: 60,height: 30))
        fengZhuangLabelAttributes(suDuLabelValue!)
        
        //初始化横线View
        hengXianView = UIView(frame:CGRect(x: 10,y: navigationHeight!+110,width: screenWidth-10,height: 0.5))
        hengXianView?.backgroundColor = UIColor(red: 200/255,green: 199/255,blue: 204/255,alpha: 1)
        
        //初始化键盘TextView
        jianPanTextView = UITextView(frame:CGRect(x: 0,y: screenHeight-120,width: screenWidth,height: 120))
        jianPanTextView?.delegate = self
//        jianPanTextView?.becomeFirstResponder()
        jianPanTextView?.keyboardType = .numberPad
        
        
        //初始化6个label对象
        firstLabel = UILabel(frame:CGRect(x: (screenWidth-240)/7,y: navigationHeight!+120,width: 40,height: 40))
        firstLabel?.layer.borderWidth = 1
        firstLabel?.layer.borderColor = UIColor.orange.cgColor
        firstLabel?.textAlignment = .center
        firstLabel?.font = UIFont.systemFont(ofSize: 12)
        
        secondLabel = UILabel(frame:CGRect(x: ((screenWidth-240)/7)*2+40*1,y: navigationHeight!+120,width: 40,height: 40))
        secondLabel?.layer.borderWidth = 1
        secondLabel?.layer.borderColor = UIColor.orange.cgColor
        secondLabel?.textAlignment = .center
        secondLabel?.font = UIFont.systemFont(ofSize: 12)
        
        thirdLabel = UILabel(frame:CGRect(x: ((screenWidth-240)/7)*3+40*2,y: navigationHeight!+120,width: 40,height: 40))
        thirdLabel?.layer.borderWidth = 1
        thirdLabel?.layer.borderColor = UIColor.orange.cgColor
        thirdLabel?.textAlignment = .center
        thirdLabel?.font = UIFont.systemFont(ofSize: 12)
        
        fourthLabel = UILabel(frame:CGRect(x: ((screenWidth-240)/7)*4+40*3,y: navigationHeight!+120,width: 40,height: 40))
        fourthLabel?.layer.borderWidth = 1
        fourthLabel?.layer.borderColor = UIColor.orange.cgColor
        fourthLabel?.textAlignment = .center
        fourthLabel?.font = UIFont.systemFont(ofSize: 12)
        
        fifthLabel = UILabel(frame:CGRect(x: ((screenWidth-240)/7)*5+40*4,y: navigationHeight!+120,width: 40,height: 40))
        fifthLabel?.layer.borderWidth = 1
        fifthLabel?.layer.borderColor = UIColor.orange.cgColor
        fifthLabel?.textAlignment = .center
        fifthLabel?.font = UIFont.systemFont(ofSize: 12)
        
        sixthLabel = UILabel(frame:CGRect(x: ((screenWidth-240)/7)*6+40*5,y: navigationHeight!+120,width: 40,height: 40))
        sixthLabel?.layer.borderWidth = 1
        sixthLabel?.layer.borderColor = UIColor.orange.cgColor
        sixthLabel?.textAlignment = .center
        sixthLabel?.font = UIFont.systemFont(ofSize: 12)
        
        //初始化6个label对象
        firstTextFieldValue = UITextField(frame:CGRect(x: (screenWidth-240)/7,y: navigationHeight!+175,width: 40,height: 40))
        firstTextFieldValue?.layer.borderWidth = 1
        firstTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        firstTextFieldValue?.textAlignment = .center
        firstTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        firstTextFieldValue?.tag = 0
//        firstTextFieldValue?.becomeFirstResponder()
        firstTextFieldValue?.keyboardType = .numberPad
        firstTextFieldValue?.delegate = self
        
        secondTextFieldValue = UITextField(frame:CGRect(x: ((screenWidth-240)/7)*2+40*1,y: navigationHeight!+175,width: 40,height: 40))
        secondTextFieldValue?.layer.borderWidth = 1
        secondTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        secondTextFieldValue?.textAlignment = .center
        secondTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        secondTextFieldValue?.tag = 1
//        secondTextFieldValue?.becomeFirstResponder()
        secondTextFieldValue?.keyboardType = .numberPad
        secondTextFieldValue?.delegate = self
        
        thirdTextFieldValue = UITextField(frame:CGRect(x: ((screenWidth-240)/7)*3+40*2,y: navigationHeight!+175,width: 40,height: 40))
        thirdTextFieldValue?.layer.borderWidth = 1
        thirdTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        thirdTextFieldValue?.textAlignment = .center
        thirdTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        thirdTextFieldValue?.tag = 2
//        thirdTextFieldValue?.becomeFirstResponder()
        thirdTextFieldValue?.keyboardType = .numberPad
        thirdTextFieldValue?.delegate = self
        
        fourthTextFieldValue = UITextField(frame:CGRect(x: ((screenWidth-240)/7)*4+40*3,y: navigationHeight!+175,width: 40,height: 40))
        fourthTextFieldValue?.layer.borderWidth = 1
        fourthTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        fourthTextFieldValue?.textAlignment = .center
        fourthTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        fourthTextFieldValue?.tag = 3
//        fourthTextFieldValue?.becomeFirstResponder()
        fourthTextFieldValue?.keyboardType = .numberPad
        fourthTextFieldValue?.delegate = self
        
        fifthTextFieldValue = UITextField(frame:CGRect(x: ((screenWidth-240)/7)*5+40*4,y: navigationHeight!+175,width: 40,height: 40))
        fifthTextFieldValue?.layer.borderWidth = 1
        fifthTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        fifthTextFieldValue?.textAlignment = .center
        fifthTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        fifthTextFieldValue?.tag = 4
//        fifthTextFieldValue?.becomeFirstResponder()
        fifthTextFieldValue?.keyboardType = .numberPad
        fifthTextFieldValue?.delegate = self
        
        sixthTextFieldValue = UITextField(frame:CGRect(x: ((screenWidth-240)/7)*6+40*5,y: navigationHeight!+175,width: 40,height: 40))
        sixthTextFieldValue?.layer.borderWidth = 1
        sixthTextFieldValue?.layer.borderColor = UIColor.orange.cgColor
        sixthTextFieldValue?.textAlignment = .center
        sixthTextFieldValue?.font = UIFont.systemFont(ofSize: 12)
        sixthTextFieldValue?.tag = 5
//        sixthTextFieldValue?.becomeFirstResponder()
        sixthTextFieldValue?.keyboardType = .numberPad
        sixthTextFieldValue?.delegate = self
        
        generateRandomNumber()
    
        
        self.view.addSubview(leftView!)
        self.view.addSubview(middleView!)
        self.view.addSubview(rightView!)
        self.view.addSubview(zhengQueShuLabel!)
        self.view.addSubview(zhengQueShuLabelValue!)
        self.view.addSubview(zhengQueLvLabel!)
        self.view.addSubview(zhengQueLvLabelValue!)
        self.view.addSubview(shiJianLabel!)
        self.view.addSubview(shiJianLabelValue!)
        self.view.addSubview(suDuLabel!)
        self.view.addSubview(suDuLabelValue!)
        self.view.addSubview(hengXianView!)
        self.view.addSubview(jianPanTextView!)
        self.view.addSubview(firstLabel!)
        self.view.addSubview(secondLabel!)
        self.view.addSubview(thirdLabel!)
        self.view.addSubview(fourthLabel!)
        self.view.addSubview(fifthLabel!)
        self.view.addSubview(sixthLabel!)
        self.view.addSubview(firstTextFieldValue!)
        self.view.addSubview(secondTextFieldValue!)
        self.view.addSubview(thirdTextFieldValue!)
        self.view.addSubview(fourthTextFieldValue!)
        self.view.addSubview(fifthTextFieldValue!)
        self.view.addSubview(sixthTextFieldValue!)
        

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
